import { useEffect } from "react";
import { HashRouter as Router } from "react-router-dom";
import nprogress from "nprogress";
import RouterPage from "./components/Router";
import { AliveScope } from "react-activation";
import { theme, ConfigProvider } from "antd";
import zhCN from "antd/es/locale/zh_CN";
import { useCommonStore } from "@/hooks/useCommonStore";
const { defaultAlgorithm, darkAlgorithm } = theme;

// 禁止进度条添加loading
nprogress.configure({ showSpinner: false });

function Page() {
    const { theme } = useCommonStore();

    useEffect(() => {
        // 关闭loading
        const firstElement = document.getElementById("first");
        if (firstElement && firstElement.style?.display !== "none") {
            firstElement.style.display = "none";
        }
    }, []);

    return (
        <Router>
            <ConfigProvider
                locale={zhCN}
                theme={{
                    algorithm: [theme === "dark" ? darkAlgorithm : defaultAlgorithm],
                }}
            >
                <AliveScope>
                    <RouterPage />
                </AliveScope>
            </ConfigProvider>
        </Router>
    );
}

export default Page;
